local extension = Package:new("qunxiongzhulu")
extension.extensionName = "king"
local U = require "packages/utility/utility"

Fk:loadTranslationTable{
  ["qunxiongzhulu"] = "群雄逐鹿",
}

Fk:loadTranslationTable{
  ["wy"] = "无涯",
}

--[[local yuyumao =  General(extension, "yuyumao", "qun", 3)
  local wy__yuyu = fk.CreateTriggerSkill{
    name = "wy__yuyu",
    anim_type = "offensive",
    events = {fk.CardUsing},
    can_trigger = function(self, event, target, player, data)
      return data.card.color == Card.Red and player:hasSkill(self) and player:usedSkillTimes(self) < 2
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local judge = {
        who = target,
        reason = self.name,
        pattern = ".",
      }
      room:judge(judge)
      if target.dead then return false end
      if judge.card.number % 2 == 1 then 
        table.insertIfNeed(data.nullifiedTargets, target.id)
      else 
        if data.card.type == Card.TypeEquip then
          room:drawCards(2, target.name)
        else
        data.additionalEffect = (data.additionalEffect or 0) + 1
        end
      end
    end
  }
  local wy__zhiyu = fk.CreateTriggerSkill{
  name = "wy__zhiyu",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return  player:hasSkill(self) and (not data.card or data.card.suit ~= Card.Spade) 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local move1 = {
      ids = room:getNCards(1),
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
      proposer = player.id,
    }
    local move2 = {
      ids = {data.card:getEffectiveId()},
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonJustMove,
      skillName = self.name,
    }
    room:moveCards(move1, move2)
    data.card = Fk:getCardById(move1.ids[1])
    room:sendLog{
      type = "#ChangedJudge",
      from = player.id,
      to = {player.id},
      card = {move1.ids[1]},
      arg = self.name
    }
  end,
  }
  yuyumao:addSkill(wy__yuyu)
  yuyumao:addSkill(wy__zhiyu)

  Fk:loadTranslationTable{
  ["yuyumao"] = "玉玉猫",
  ["designer:yuyumao"] = "无涯",

  ["wy__yuyu"] = "玉玉",
  [":wy__yuyu"] = "锁定技，当有角色每回合使用前两张黑色牌时，你令其进行掷骰，若点数为:奇数，此牌无效;偶数，此牌额外执行一次，若为装备牌则改为摸两张牌。",
  ["wy__zhiyu"] = "治玉？",
  [":wy__zhiyu"] = "当“玉玉”的掷骰结果出现后，你可以弃置一张基本牌令结果反转。",

}]]

local wy__simayi =  General(extension, "wy__simayi", "wei", 4)
  wy__simayi.hidden = true
  local wy__guikuang =  fk.CreateTriggerSkill{
    name = "wy__guikuang",
    anim_type = "offensive",
    events = {"fk.GeneralAppeared"},
    can_trigger = function (self, event, target, player, data)
      return  target == player and player:hasShownSkill(self) 
    end,
    on_cost = function (self, event, target, player, data)
      return true
    end,
    on_use = function (self, event, target, player, data)
      local room = player.room
      if room:getTag("RoundCount") < 3 then
      room:askForGuanxing(player, room:getNCards(3))
      else
      room:askForGuanxing(player, room:getNCards(math.min(7,room:getTag("RoundCount"))))
      end
    end,
  }
  local wy__guikuang__yinni = fk.CreateTriggerSkill{
  name = "wy__guikuang__yinni",
  anim_type = "offensive",
  events = {fk.Damaged,},
  on_use = function(self, event, target, player, data)
    if target == player and player:hasSkill(wy__guikuang) then 


    end
  end,
  }
  local wy__zhongluan =  fk.CreateTriggerSkill{
    name = "wy__zhongluan",
    events = {fk.Damaged},
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and player:usedSkillTimes(self) ==0 and data.card and player.room:getCardArea(data.card) == Card.Processing
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      player:drawCards(2, self.name)
      local cards = player.room:askForDiscard(data.to, 1, 999, true, self.name, false, ".", "#wy__zhongluan-discard", true)
      if #cards == 0 then return end
      if table.find(cards, function(id) return Fk:getCardById(id).type == Card.TypeBasic end) then
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#wy__zhongluan-Basic-choose:", self.name, false)
        end
      if table.find(cards, function(id) return Fk:getCardById(id).type == Card.TypeEquip end) then
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#wy__zhongluan-Equip-choose:", self.name, false)
        end
      if table.find(cards, function(id) return Fk:getCardById(id).type == Card.TypeTrick end) then
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#wy__zhongluan-Trick-choose:", self.name, false)
        local judge = {
          who = tos,
          reason = self.name,
          pattern = ".",
        }
        room:judge(judge)
        if tos.dead then return false end
        if judge.card.color == Card.Red then
          if tos:isWounded() then
            room:recover({
              who = tos,
              num = 1,
              recoverBy = player,
              skillName = self.name
            })
          end
      end
    end
  end,
  }

  wy__guikuang:addRelatedSkill(wy__guikuang__yinni)
  wy__simayi:addSkill(wy__zhongluan)
  wy__simayi:addSkill(wy__guikuang)


  Fk:loadTranslationTable{
  ["wy__simayi"] = "司马懿",
  ["designer:wy__simayi"] = "无涯",

  ["wy__zhongluan"] = "忠乱",
  [":wy__zhongluan"] = "每回合限一次，当有角色受到伤害时，你可摸两张牌然后弃置至少一张牌，若你弃置的牌中有:基本牌:令一名角色获得造成伤害的牌:锦囊牌:令一名角色进行一次判定，若为红色其回复一点体力;装备牌，令一名角色流失一点体力。",
  ["wy__guikuang"] = "诡诳",
  [":wy__guikuang"] = "锁定技，当你受到伤害后，你令下次受到的伤害无效。当你令受到的伤害无效时，你观看牌堆顶X张牌，你可以将这些牌置于场上或以任意顺序置于牌堆顶或牌堆底(X为游戏轮数且至少为三，至多为七)",

  ["#wy__zhongluan-discard"] = "忠乱:请选择弃置的牌",
  ["#wy__zhongluan-Basic-choose"] = "忠乱:令一名角色获得造成伤害的牌",
  ["#wy__zhongluan-Equip-choose"] = "忠乱:令一名角色流失一点体力",
  ["#wy__zhongluan-Trick-choose"] = "忠乱:令一名角色进行一次判定，若为红色其回复一点体力",

}

local wy__caopi =  General(extension, "wy__caopi", "wei", 4)
  local wy__fangzhu =  fk.CreateTriggerSkill{
    name = "wy__fangzhu",
    anim_type = "offensive",
    events = {fk.Damaged},
    on_cost = function(self, event, target, player, data)
      local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper)
      , 1, 1, "#wz__fangzhu-choose:::"..player:getLostHp(), self.name, true)
      if #to > 0 then
        self.cost_data = {tos = to}
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local to = player.room:getPlayerById(self.cost_data.tos[1])
      local n = player.hp+1
      room:drawCards(to,n, self.name)
      to:turnOver()
    end
  }
  local wy__xingshang =  fk.CreateTriggerSkill{
    name = "wy__xingshang",
    anim_type = "offensive",
    events = {fk.TurnedOver},
    can_trigger = function(self, event, target, player, data)
      return  player:hasSkill(self) and player ~= target and event == fk.TurnedOver and
      target:getMark("wy__xingshang-turn") == 0 
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      if event == fk.TurnedOver then
        local n = player.hp
        local cards = target:getCardIds("hej")
        if #cards > 0 then
          cards = room:askForCardsChosen(player, target, 1, n, "hej", self.name)
          room:obtainCard(player, cards, false, fk.ReasonPrey)
          room:addTableMark(target, "wy__xingshang-turn",  target.id)
          if target.hp > player.hp then
            room:loseHp(target,1,self.name)
          end
      end
    end
    end,
  }
  local wy__xingshang__duel = fk.CreateTriggerSkill{
  name = "#wy__xingshang__duel",
  anim_type = "offensive",
  events = {fk.TurnedOver},
  can_trigger = function(self, event, target, player, data)
    return  player:hasSkill(wy__xingshang) and player ~= target and (event == fk.TurnedOver and target.faceup)
    end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not target:isProhibited(player, Fk:cloneCard("duel")) and room:askForSkillInvoke(player, wy__xingshang.name, nil, "#wy__xingshang-duel::"..player.id) then
    room:useVirtualCard("duel", nil, target, player, self.name, true)
    end
  end,
  }
  wy__xingshang:addRelatedSkill(wy__xingshang__duel)
  wy__caopi:addSkill(wy__fangzhu)
  wy__caopi:addSkill(wy__xingshang)
  Fk:loadTranslationTable{
  ["wy__caopi"] = "曹丕",
  ["designer:wy__caopi"] = "无涯",

  ["wy__fangzhu"] = "放逐",
  [":wy__fangzhu"] = "当你受到伤害时，你可令一名其他角色翻面并摸X+1张牌(X为你的体力值)",
  ["wy__xingshang"] = "行殇",
  [":wy__xingshang"] = "每回合每名角色限一次，当一名角色翻面时，你可获得其X张牌，若其体力值大于你，你令其流失会点体力;当一名角色武将牌翻回正面时，你可令其视为对你使用一张「决斗」",
  ["#wy__xingshang__duel"] = "行殇-决斗",
  ["#wy__xingshang-duel"] = "行殇:是否令其视为对你使用一张【决斗】",
  ["#wz__fangzhu-choose"] = "放逐:令一名其他角色翻面并摸X+1张牌(X为你的体力值)",
}

local wy__sunwu =  General(extension, "wy__sunwu", "god", 4)
wy__sunwu.hidden = true




Fk:loadTranslationTable{
  ["wy__sunwu"] = "孙武",
}




Fk:loadTranslationTable{
  ["hqy"] = "焕晴缘",
}

local hqy__xujing = General(extension, "hqy__xujing", "shu", 3)
local hqy__caixia = fk.CreateTriggerSkill{
  name = "hqy__caixia",
  events = {fk.Damage, fk.Damaged, fk.CardUsing,fk.GameStart},
  mute = true,
  can_trigger = function(self, event, target, player, data)
      if event == fk.Damage or event == fk.Damaged or event == fk.CardUsing then
          return player == target and player:hasSkill(self)
      else
          return player:hasSkill(self)
      end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.GameStart then
      local room = player.room
      local n = math.min(5, #room.players)
      self.cost_data =n
      return true
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      player.room:setPlayerMark(player, "@caixia", self.cost_data)
    elseif event == fk.CardUsing and player:getMark("@caixia") > 0 then
          room:removePlayerMark(player, "@caixia")
    elseif event == fk.Damage or event == fk.Damaged and  player:getMark("@caixia") < 1 then
          room:drawCards(player, self.cost_data, self.name)
          player.room:setPlayerMark(player, "@caixia", self.cost_data)
          local card
          card = room:printCard("crossbow", Card.Heart, 1)
          room:moveCardTo(card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, nil, true, player.id)
    end
  end,
}
hqy__xujing:addSkill(hqy__caixia)
Fk:loadTranslationTable{
  ["hqy__xujing"] = "许靖",
  ["designer:hqy__xujing"] = "焕晴缘",
  ["hqy__caixia"] = "才瑕",
  [":hqy__caixia"] = "当你使用X张牌后造成或受到伤害次数时，你可以摸X张牌（X为游戏人数且至多为5）,且从游戏外获得一个【诸葛连弩】。",
  ["@caixia"] = "才瑕",
}


local hqy__wangji = General(extension, "hqy__wangji", "wei", 3)
local hqy__qizhi = fk.CreateTriggerSkill{
name = "hqy__qizhi",
events = {fk.CardUsing },
can_trigger = function(self, event, target, player, data)
  return target == player and player:hasSkill(self) 
end,
on_cost = function(self, event, target, player, data)
  local room = player.room
  local to = room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#qizhi-choose", self.name, true)
  if #to > 0 then
    self.cost_data = to[1]
    return true
  end
end,
on_use = function(self, event, player, target, data)
  local room = player.room
  local to = room:getPlayerById(self.cost_data)
  local id = room:askForCardChosen(player, to, "hej", self.name)
  room:throwCard({id}, self.name, to, player)
  if not to.dead then
    to:drawCards(1, self.name)
  end
end,
}
local hqy__jinqu = fk.CreateTriggerSkill{
name = "hqy__jinqu",
anim_type = "drawcard",
events = {fk.TurnEnd},
can_trigger = function(self, event, target, player, data)
  return player:hasSkill(self) 
end,
on_use = function(self, event, target, player, data)
  local n = player:usedSkillTimes("hqy__qizhi", Player.HistoryTurn)
  if n < 1 then 
    player:drawCards(1, self.name)
  else
    player:drawCards(n, self.name)
  end
  player.room:askForDiscard(player, 2, 2, false, self.name, false)
end,
}
local hqy__qiqu = fk.CreateViewAsSkill{
name = "hqy__qiqu",
pattern = "dismantlement,nullification,ex_nihilo",
interaction = function()
  local names, all_names = {} , {}
  for _, id in ipairs(Fk:getAllCardIds()) do
    local card = Fk:getCardById(id)
    if (card.name == "dismantlement" or card.name == "nullification" or card.name == "ex_nihilo" ) and not card.is_derived and not table.contains(all_names, card.name) then
      table.insert(all_names, card.name)
      local to_use = Fk:cloneCard(card.name)
      if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
      (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
        table.insert(names, card.name)
      end
    end
  end
  if #names == 0 then return false end
  return UI.ComboBox { choices = names, all_choices = all_names }
end,
card_filter = function(self, to_select, selected)
  return #selected == 0
end,
view_as = function(self, cards)
  if #cards ~= 1 or not self.interaction.data then return end
  local card = Fk:cloneCard(self.interaction.data)
  card:addSubcards(cards)
  card.skillName = self.name
  return card
end,
enabled_at_play = function(self, player)
  return player:usedSkillTimes(self.name) == 0
end,
enabled_at_response = function(self, player, response)
  return  player:usedSkillTimes(self.name) == 0
end,
}

hqy__wangji:addSkill(hqy__qizhi)
hqy__wangji:addSkill(hqy__jinqu)
hqy__wangji:addSkill(hqy__qiqu)


Fk:loadTranslationTable{
  ["hqy__wangji"] = "王基",

  ["hqy__qizhi"] = "奇制",
  [":hqy__qizhi"] = "当你使用一张牌后，你可以弃置一名角色的一张牌，然后令其摸一张牌。",
  ["hqy__jinqu"] = "进趋",
  [":hqy__jinqu"] = "每个回合结束后，你可以摸X张牌，然后将弃置两张牌（X为你本回合发动〖奇制〗的次数且至少为1）。",
  ["@hqy__qizhi-turn"] = "奇制",
  ["#hqy__qizhi-choose"] = "奇制：你可以弃置一名角色一张牌，然后其摸一张牌",
  ["hqy__qiqu"] = "奇趋",
  [":hqy__qiqu"] = "每回合限一次，你可弃置一张牌视为使用一张智囊牌。",

  ["$qizhi1"] = "声东击西，敌寇一网成擒。",
  ["$qizhi2"] = "吾意不在此地，已遣别部出发。",
  ["$jinqu1"] = "建上昶水城，以逼夏口！",
  ["$jinqu2"] = "通川聚粮，伐吴之业，当步步为营。",
  ["~wangji"] = "天下之势，必归大魏，可恨，未能得见呐！",
}

local hqy__liuyu = General(extension, "hqy__liuyu", "qun", 3,4)
hqy__liuyu.hidden = true
--[[local hqy__fumin = fk.CreateTriggerSkill{
name = "hqy__fumin",
events = {fk.Damaged,fk.EventPhaseStart},
can_trigger = function(self, event, target, player, data)
  if event == fk.EventPhaseStart then 
    return target == player and player:hasSkill(self) and player.phase == Player.Start
  else
    return target == player and player:hasSkill(self)
  end
end,
on_use = function(self, event, target, player, data)
  local room = player.room
  local kingdoms = {}
  for _, p in ipairs(room.alive_players) do
    table.insertIfNeed(kingdoms, p.kingdom)
  end
  player:drawCards(#kingdoms + 1, self.name)
  room:askForYiji(player, player:getCardIds("h"), room:getOtherPlayers(player), self.name, #kingdoms - 1, #kingdoms - 1)
end,
}
local hqy__taoni = fk.CreateTriggerSkill{
name = "hqy__taoni",
events = {fk.RoundStart,fk.RoundEnd},
can_trigger = function(self, event, target, player, data)
  if event == fk.RoundStart then 
  return player:hasSkill(self) and not player:isKongcheng()
  else
    return player:hasSkill(self) 
  end
end,
on_cost = function(self, event, target, player, data)
  return player.room:askForSkillInvoke(player, self.name, nil, "#xingchong-invoke:::"..tostring(player.maxHp))
end,
on_use = function(self, event, target, player, data)
  if event == fk.RoundStart then 
    local n = player.hp
    local cards = player.room:askForCard(player, 1, n, false, self.name, true, ".", "#hqy__taoni-invoke")
    if #cards > 0 then
      player:showCards(cards)
      if not player.dead then
        local mark = {}
        for _, id in ipairs(cards) do
          if player.room:getCardArea(id) == Card.PlayerHand and player.room:getCardOwner(id) == player then
            table.insert(mark, id)
            player.room:setCardMark(Fk:getCardById(id), "@@hqy__taoni-inhand", 1)
          end
        end
        player.room:setPlayerMark(player, "hqy__taoni-round", mark)
      end
    end
  end
end,
on_use = function(self, event, target, player, data)
  local room = player.room 
  if event == fk.RoundStart then 
  room:recover{ who = player, num = 1, skillName = self.name }
  local to = room:getPlayerById(data.from)
  if to.dead or to:isNude() then return end
  local id = room:askForCardChosen(player, to, "he", self.name)
  room:throwCard({id}, self.name, to, player)
  end
end,



refresh_events = {fk.RoundEnd},
can_refresh = Util.TrueFunc,
on_refresh = function(self, event, target, player, data)
  local room = player.room
  for _, id in ipairs(player:getCardIds(Player.Hand)) do
    room:setCardMark(Fk:getCardById(id), "@@hqy__taoni-inhand", 0)
  end
end,
}
local xingchong_delay = fk.CreateTriggerSkill{
name = "#xingchong_delay",
mute = true,
events = {fk.AfterCardsMove},
can_trigger = function(self, event, target, player, data)
  if player.dead or type(player:getMark("xingchong-round")) ~= "table" then return false end
  local mark = player:getMark("xingchong-round")
  for _, move in ipairs(data) do
    if move.from == player.id then
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.PlayerHand and table.contains(mark, info.cardId) then
          return true
        end
      end
    end
  end
end,
on_cost = Util.TrueFunc,
on_use = function(self, event, target, player, data)
  local room = player.room
  local mark = player:getMark("xingchong-round")
  local x = 0
  for _, move in ipairs(data) do
    if move.from == player.id then
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.PlayerHand and table.removeOne(mark, info.cardId) then
          x = x + 2
        end
      end
    end
  end
  room:setPlayerMark(player, "xingchong-round", #mark > 0 and mark or 0)
  if x > 0 then
    room:drawCards(player, x, xingchong.name)
  end
end,
}
local hqy__zongqing = fk.CreateTriggerSkill{
name = "hqy__zongqing" ,
frequency = Skill.Compulsory,
events = {fk.Damaged},
can_trigger = function(self, event, target, player, data)
  return player:hasSkill(self) and target == player and data.from and data.from.kingdom ~= "qun" and data.from ~= player and
  not data.from.dead and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and
  #player.room.logic:getActualDamageEvents(2, function(e)
    return e.data[1].from == data.from and e.data[1].to == player
  end) == 0
end,
on_use = function(self, event, target, player, data)
  local room = player.room 
  room:recover{ who = player, num = 1, skillName = self.name }
  local to = room:getPlayerById(data.from)
  if to.dead or to:isNude() then return end
  local id = room:askForCardChosen(player, to, "he", self.name)
  room:throwCard({id}, self.name, to, player)
end,
}

hqy__liuyu:addSkill(hqy__fumin)
hqy__liuyu:addSkill(hqy__taoni)
hqy__liuyu:addSkill(hqy__zongqing)]]
Fk:loadTranslationTable{
["hqy__liuyu"] = "刘虞",

["hqy__fumin"] = "抚民",
[":hqy__fumin"] = "出牌阶段开始或当你受到伤害时，你可以摸X张牌，然后将X-1张牌分配给其他角色；若其为【群】势力角色，你可令其选择额外摸一张牌或使用之（X为场上势力数+1）。",
["hqy__taoni"] = "讨逆",
[":hqy__taoni"] = "每轮开始时，你可以以展示至多体力值值张手牌；若如此做，每轮结束时，若所有展示牌均离开你的手牌区，你可以将牌堆底的牌当作等量张【杀】对一名本轮造成过伤害的角色使用。",
["hqy__zongqing"] = "宗亲",
[":hqy__zongqing"] = "锁定技，非群势力角色首次对你造成伤害时，你回复一点体力并弃置其两张牌。",

["hqy__taoni-invoke"] = "展示至多%arg张手牌",
}

local hqy__qi_xunyu = General(extension, "hqy__qi_xunyu", "qun", 3,4)
hqy__qi_xunyu.hidden = true
--[[local hqy__xiansu = fk.CreateTriggerSkill{
name = "hqy__xiansu",
events = {fk.GameStart},
can_trigger = function(self, event, target, player, data)
  return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
end,
on_use = function(self, event, target, player, data)
  local room = player.room
  local n = room.game.start_players
  local cards = room:askForCard(player, 4*n, 4*n, false, self.name, true, ".", "#hqy__xiansu-invoke")
  if #cards > 0 then
    player:showCards(cards)
    local mark = {}
    for i, id in ipairs(cards) do
      if i <= n then
        room:setCardMark(Fk:getCardById(id), "@@hqy__xiansu-top"..i, 1)
      else
        room:setCardMark(Fk:getCardById(id), "@@hqy__xiansu-bottom"..(i-n), 1)
      end
      table.insert(mark, id)
    end
    room:setPlayerMark(player, "hqy__xiansu-cards", mark)
  end
end,
on_use = function(self, event, target, player, data)
  local room = player.room
  local n = room.game.start_players
  local cards = room:askForCard(player, 2, 2, false, self.name, true, ".", "#hqy__xiansu-invoke")
  if #cards > 0 then
    player:showCards(cards)
    player:recover(2, self.name)
    room:setPlayerMark(player, "hqy__xiansu-cards", nil)
    room:setPlayerMark(player, "hqy__xiansu-top", nil)
    room:setPlayerMark(player, "hqy__xiansu-bottom", nil)
  end
end,
}



--zhanying]]
Fk:loadTranslationTable{
["hqy__qi_xunyu"] = "奇荀彧",

["hqy__xiansu"] = "先夙",
[":hqy__xiansu"] = "锁定技;每局游戏限1次;每轮开始时，你观看牌堆顶4X张牌并调整其中至多X张牌的位置(X为游戏开始时角色数)，然后你令1名角色摸2张牌并令你体力上限+1。",
["hqy__shicai"] = "识才",
[":hqy__shicai"] = "每名角色限1次;当其首次脱离濒死状态时，你可减一点体力上限并令其体力上限+1，然后你摸2张牌并重置“先夙”。",

}


local hqy__machao = General(extension, "hqy__machao", "qun", 4)
hqy__machao.hidden = true
--[[local hqy__aozhen = fk.CreateTriggerSkill{
name = "hqy__aozhen",
events = {fk.TargetSpecified},
can_trigger = function(self, event, target, player, data)
  return target ~= player and player:hasSkill(self) and player.phase == Player.Play
end,
on_use = function(self, event, target, player, data)
  local room = player.room
  local to = room:getPlayerById(data.to)
  local num = #to:getCardIds(Player.Hand)
  if num >= player.hp then
    local choices = {"draw","get","cancel"}
    if choices == "draw" then
      room:drawCards(player,1,self.name)
    elseif choices == "get" then 
      local card = room:askForCardChosen(player, to, "he", self.name)
      room:obtainCard(player.id, card, false, fk.ReasonPrey)
    elseif choices == "cancel" then
      return end
  elseif num <=player.hp then
    data.disresponsiveList = data.disresponsiveList or {}
    table.insert(data.disresponsiveList, data.to)
  end
end,
}
local hqy__xiongjue = fk.CreateTriggerSkill{
name = "hqy__xiongjue", 
events = {fk.GameStart,fk.Death},
can_trigger = function(self, event, target, player, data)
  if event == fk.GameStart then
    return player:hasSkill(self, false, true)
  else 
    return player:hasSkill(self, false, true) and target:getMark("@@hqy__xiongjue_chou") > 0
  end
end,
on_cost = Util.TrueFunc,
on_use = function(self, event, target, player, data)
  local room = player.room
  local mark = player:getTableMark("@@hqy__xiongjue_chou")
  local tos = table.map(table.filter(room.alive_players, function(p)
    return p ~= player and not table.contains(mark, p.id)
  end), Util.IdMapper)
  if #tos == 0 then return false end
  tos = room:askForChoosePlayers(player, tos, 1, 1, "#hqy__xiongjue-choose", self.name, false)
  table.insert(mark, tos[1])
  room:setPlayerMark(room:getPlayerById(tos[1]), "@@hqy__xiongjue_chou", 1)
end,
}
local hqy__xiongjue_damage = fk.CreateTriggerSkill{
name = "#hqy__xiongjue_damage",
events = {fk.Damage},
can_trigger = function(self, event, target, player, data)
  return target == player and player:hasSkill(hqy__xiongjue) and data.to ~= player
end,
on_cost = Util.TrueFunc,
on_use = function(self, event, target, player, data)
  local room = player.room
  local to = room:getPlayerById(data.to)
  room:addPlayerMark(to, "@@hqy__xiongjue-turn")
  room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity .. "-turn")
  if to:getMark("@@hqy__xiongjue_chou") > 0 then
    to:throwAllCards("e")
  end
end,
}
local hqy__xiongjue_slash = fk.CreateTriggerSkill{
name = "#hqy__xiongjue_slash",
events = {fk.RoundStart,fk.TurnEnd,fk.Damaged},
can_trigger = function(self, event, target, player, data)
  if event == fk.RoundStart  then
    return player:hasSkill(hqy__xiongjue) 
  elseif event == fk.TurnEnd then
    return  player:hasSkill(hqy__xiongjue) and target:getMark("@@hqy__xiongjue_chou") > 0
  else
    return player:hasSkill(hqy__xiongjue) and target == player and math.max(0, player.hp) + player.shield <= data.damage
  end
end,
on_cost = function(self, event, target, player, data)
  local room = player.room
  local names = {}
  for name, _ in pairs(Fk.all_card_types) do
    local card = Fk:cloneCard(name)
    if not card.is_derived and card.trueName == "slash" then  
      table.insertIfNeed(names, name)
    end
  end
  if #names ~= 0 then 
    local choice = room:askForChoice(player, names, self.name)
    if #choice > 0 then
      self.cost_data = {choice,}
    else return end
  else return end
  local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#hqy__xiongjue_slash-choose", self.name, true)
  if #tos > 0 then
    self.cost_data = {self.cost_data[1],tos}
  return true
  end
end,
on_use = function(self, event, target, player, data)
  local room = player.room
  room:drawCards(player, 1, self.name)
  local slash = Fk:cloneCard(self.cost_data[1])
  slash.skillName = self.name
  local use = {
    from = player.id,
    to = self.cost_data[2],
    card = slash,
    extraUse = true,
  }
  room:useCard(use)
end,

    local cards = table.filter(player:getMark(self.name), function (id)
      return table.find(player:getPile("yanzuo"), function (id2)
        return Fk:getCardById(id).name == Fk:getCardById(id2).name
      end)
    end)
    if #cards > 0 then
      local use = U.askForUseRealCard(room, player, cards, nil, self.name,
        "#yanzuo-ask", {expand_pile = cards, bypass_times = true}, true, false)
      if use then
        local card = Fk:cloneCard(use.card.name)
        card.skillName = self.name
        room:useCard{
          card = card,
          from = player.id,
          tos = use.tos,
          extraUse = true,
        }
      end
    end


}
hqy__xiongjue:addRelatedSkill(hqy__xiongjue_damage)
hqy__xiongjue:addRelatedSkill(hqy__xiongjue_slash)
hqy__machao:addSkill(hqy__xiongjue)
hqy__machao:addSkill(hqy__aozhen)]]
Fk:loadTranslationTable{
["hqy__machao"] = "马超",

["hqy__aozhen"] = "鏖阵",
[":hqy__aozhen"] = "你使用牌指定角色为目标时，若其手牌数不小于体力值，你可获得其1张牌或摸1张牌;不大于体力值，其无法响应该牌。",
["hqy__xiongjue"] = "雄决",
[":hqy__xiongjue"] = "游戏开始或“仇”角色阵亡时，你令1名其他角色获得“仇”。你对其他角色造成伤害时，你可令其本回合非锁定技失效;若为“仇”角色，你弃置其所有装备牌。你可于以下时机摸1张牌并视为使用1张无距离限制的任意【杀】:1、每轮开始时;2、“仇”角色回合结束时;3、你即将受到致命伤害时。",
["@@hqy__xiongjue_chou"] = "仇",
["@@hqy__xiongjue-turn"] = "雄决",
["hqy__xiongjue-choose"] = "雄决：令一名其他角色获得“仇”标记。"
}



Fk:loadTranslationTable{
  ["yzx"] = "樱之下",
}


local y_lukang = General(extension, "y_lukang", "wu", 4)
y_lukang.hidden = true
--[[local y_zhudi = fk.CreateTriggerSkill{
  name = "y_zhudi",
  anim_type = "offensive",
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  on_use = function(self, event, player, data)
    local room = player.room
    if event == fk.GameStart then
      room:moveCardIntoEquip(player, U.prepareDeriveCards(room, {{"ty__drowning_Weapon", Card.Diamond, 6}}, "ty__drowning_derivecards"), self.name)
      room:moveCardIntoEquip(player, U.prepareDeriveCards(room, {{"ty__drowning_Armor", Card.Diamond, 6}}, "ty__drowning_derivecards"), self.name)
      room:moveCardIntoEquip(player, U.prepareDeriveCards(room, {{"ty__drowning_DefensiveRide", Card.Diamond, 6}}, "ty__drowning_derivecards"), self.name)
      room:moveCardIntoEquip(player, U.prepareDeriveCards(room, {{"ty__drowning_OffensiveRide", Card.Diamond, 6}}, "ty__drowning_derivecards"), self.name)
      room:moveCardIntoEquip(player, U.prepareDeriveCards(room, {{"ty__drowning_Treasure", Card.Diamond, 6}}, "ty__drowning_derivecards"), self.name)
      room:setCardMark(Fk:getCardById("ty__drowning_Weapon"), MarkEnum.DestructOutMyEquip, 1)
      room:moveCardIntoEquip(player, "ty__drowning_Weapon", self.name, true, player)
      room:setCardMark(Fk:getCardById("ty__drowning_Armor"), MarkEnum.DestructOutMyEquip, 1)
      room:moveCardIntoEquip(player, "ty__drowning_Armor", self.name, true, player)
      room:setCardMark(Fk:getCardById("ty__drowning_DefensiveRide"), MarkEnum.DestructOutMyEquip, 1)
      room:moveCardIntoEquip(player, "ty__drowning_DefensiveRide", self.name, true, player)
      room:setCardMark(Fk:getCardById("ty__drowning_OffensiveRide"), MarkEnum.DestructOutMyEquip, 1)
      room:moveCardIntoEquip(player, "ty__drowning_OffensiveRide", self.name, true, player)
      room:setCardMark(Fk:getCardById("ty__drowning_Treasure"), MarkEnum.DestructOutMyEquip, 1)
      room:moveCardIntoEquip(player, "ty__drowning_Treasure", self.name, true, player)
  end
end,
} 

local y_powei = fk.CreateTriggerSkill{
  name = "y_powei",
  frequency = Skill.Compulsory,
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
  return target == player and player:hasSkill(self) and player.phase == Player.Play and #player:getAvailableEquipSlots() > 0
  end,
  on_use = function(self, room, effect,data,player)
    local player = room:getPlayerById(effect.from)
    local choice = room:askForChoices(player, player:getAvailableEquipSlots(), 1, 1, self.name, "#y_powei-abort", false)
    room:abortPlayerArea(player, choice)
    if choice == "WeaponSlot"
    then player:drawCards(1, self.name, nil, "@@wuqi")
    elseif choice == "ArmorSlot"
    then player:drawCards(1, self.name, nil, "@@fangju")
    elseif choice == "DefensiveRideSlot"
    then player:drawCards(1, self.name, nil, "@@-1")
    elseif choice =="OffensiveRideSlot"
    then player:drawCards(1, self.name, nil, "@@+1")
    elseif choice =="TreasureSlot"
    then player:drawCards(1, self.name, nil, "@@baowu")
    end
  end,
}
local y_powei_card = fk.CreateTriggerSkill{
  name = "#y_powei_card",
  events  = {fk.EventPhaseStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and  player:hasSkill(self) and player.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    if  #player:getEquipments(Card.SubtypeWeapon)== 0  then
      player:drawCards(2, self.name, nil, "@@wuqi")
    elseif #player:getEquipments(Card.SubtypeArmor)== 0  then
      player:drawCards(2, self.name, nil, "@@fangju")
    elseif  #player:getEquipments(Card.SubtypeDefensiveRide)== 0 then
      player:drawCards(2, self.name, nil, "@@-1")
    elseif  #player:getEquipments(Card.SubtypeOffensiveRide) == 0 then
      player:drawCards(2, self.name, nil, "@@+1")
    elseif  #player:getEquipments(Card.SubtypeTreasure) == 0 then
      player:drawCards(2, self.name, nil, "@@baowu")
    end
  end,
}
local y_powei_maxcard = fk.CreateTriggerSkill{
  name = "#y_powei_maxcard",
  exclude_from = function(self, player, card)
    return card:getMark("@@baowu") > 0 and card:getMark("@@fangju") > 0 and card:getMark("@@-1") > 0 and card:getMark("@@+1") > 0 and card:getMark("@@wuqi") > 0 
  end,
}
local y_powei_hp = fk.CreateTriggerSkill{
  name = "#y_powei_hp",
  events = {fk.EventPhaseStart},
  can_refresh = function(self,  player, card)
    return   player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_use = function(self, player,card)
    local n = player.hp
    local room = player.room
    room:throwCard(player:getCardIds(Player.Hand), self.name, player, player)
    if #player:getEquipments(Card.SubtypeWeapon) == 0 and card:getMark("@@wuqi") > n  then
      room:throwCard(player:getCardIds(card:getMark("@@wuqi")), n - #card:getMark("@@wuqi"),self.name, player, player)
    elseif  #player:getEquipments(Card.SubtypeArmor) == 0 and card:getMark("@@fangju") > n then
      room:throwCard(player:getCardIds(card:getMark("@@fangju")), n - #card:getMark("@@fangju"),self.name, player, player)
    elseif  #player:getEquipments(Card.SubtypeDefensiveRide)== 0 and card:getMark("@@-1") > n then
      room:throwCard(player:getCardIds(card:getMark("@@-1")), n - #card:getMark("@@-1"),self.name, player, player)
    elseif  #player:getEquipments(Card.SubtypeOffensiveRide) == 0 and card:getMark("@@+1") > n then
      room:throwCard(player:getCardIds(card:getMark("@@+1")), n - #card:getMark("@@+1"),self.name, player, player)
    elseif  #player:getEquipments(Card.SubtypeTreasure) == 0 and card:getMark("@@baowu") > n then
      room:throwCard(player:getCardIds(card:getMark("@@baowu")), n - #card:getMark("@@baowu"),self.name, player, player)
    end
  end,
}
local y_powei_throw = fk.CreateTriggerSkill{
  name = "y_powei_throw",
  events = {fk.AfterCardsMove},
  can_refresh = function(self, data,target, player, card)
    return target == player and  player:hasSkill(self) 
  end,
  on_use = function(self, data,target, player, card)
    local room = player.room
    if data.card:getMark("@@wuqi") ~= 0 and #player:getEquipments(Card.SubtypeWeapon) ~= 0 then
      room:throwCard(player:getCardIds(card:getMark("@@wuqi")),self.name, player, player)
    elseif data.card:getMark("@@fangju") ~= 0 and #player:getEquipments(Card.SubtypeArmor) ~= 0 then
      room:throwCard(player:getCardIds(card:getMark("@@fangju")),self.name, player, player)
    elseif data.card:getMark("@@-1") ~= 0 and #player:getEquipments(Card.SubtypeDefensiveRide) ~= 0 then
      room:throwCard(player:getCardIds(card:getMark("@@-1")),self.name, player, player)
    elseif data.card:getMark("@@+1") ~= 0 and #player:getEquipments(Card.SubtypeOffensiveRide) ~= 0 then
      room:throwCard(player:getCardIds(card:getMark("@@+1")),self.name, player, player)
    elseif data.card:getMark("@@baowu") ~= 0 and #player:getEquipments(Card.SubtypeTreasure) ~= 0 then
      room:throwCard(player:getCardIds(card:getMark("@@baowu")),self.name, player, player)
    end
  end,
}
local y_lianying_card = fk.CreateTriggerSkill{
  name = "#y_lianying_card",
  events  = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    return target == player and  player:hasSkill(self) 
  end,
  on_use = function(self, event, target, player, data)
    if data.card:getMark("@@wuqi") == 0 and #player:getEquipments(Card.SubtypeWeapon) == 0 then
      player:drawCards(1, self.name, nil, "@@wuqi")
    elseif data.card:getMark("@@fangju") == 0 and #player:getEquipments(Card.SubtypeArmor) == 0 then
      player:drawCards(1, self.name, nil, "@@fangju")
    elseif data.card:getMark("@@-1") == 0 and #player:getEquipments(Card.SubtypeDefensiveRide)== 0 then
      player:drawCards(1, self.name, nil, "@@-1")
    elseif data.card:getMark("@@+1") == 0 and #player:getEquipments(Card.SubtypeOffensiveRide) == 0 then
      player:drawCards(1, self.name, nil, "@@+1")
    elseif data.card:getMark("@@baowu") == 0 and #player:getEquipments(Card.SubtypeTreasure) == 0 then
      player:drawCards(1, self.name, nil, "@@baowu")
    end
  end,
}

local y_lianying = fk.CreateTriggerSkill{
  name = "y_lianying",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if not player:isKongcheng() then return end
    for _, move in ipairs(data) do
      if move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
local y_lianying_card = fk.CreateTriggerSkill{
  name = "#y_lianying_card",
  events  = {fk.AfterCardsMove},
  can_refresh = function(self,  player,target, card,data)
    return target == player and  player:hasSkill(self) 
  end,
  on_use = function(self, player, target,data,card)
    if data.card:getMark("@@wuqi") == 0 and #player:getEquipments(Card.SubtypeWeapon) == 0 then
      player:drawCards(1, self.name, nil, "@@wuqi")
    elseif data.card:getMark("@@fangju") == 0 and #player:getEquipments(Card.SubtypeArmor) == 0 then
      player:drawCards(1, self.name, nil, "@@fangju")
    elseif data.card:getMark("@@-1") == 0 and #player:getEquipments(Card.SubtypeDefensiveRide)== 0 then
      player:drawCards(1, self.name, nil, "@@-1")
    elseif data.card:getMark("@@+1") == 0 and #player:getEquipments(Card.SubtypeOffensiveRide) == 0 then
      player:drawCards(1, self.name, nil, "@@+1")
    elseif data.card:getMark("@@baowu") == 0 and #player:getEquipments(Card.SubtypeTreasure) == 0 then
      player:drawCards(1, self.name, nil, "@@baowu")
    end
  end,
}
local y_jueyan = fk.CreateTriggerSkill{
  name = "y_jueyan",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  can_wake = function(self, event, target, player, data)
    return player:hasEmptyEquipSlot() 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, -1)
    room:handleAddLoseSkills(player,y_lianying , nil)
    room:handleAddLoseSkills(player,y_powei , nil)
    room:handleAddLoseSkills(player,"huairou" , nil)
  end,
}
y_powei:addRelatedSkill(y_powei_maxcard)
y_powei:addRelatedSkill(y_powei_throw)
y_powei:addRelatedSkill(y_powei_card)
y_powei:addRelatedSkill(y_powei_hp)
y_lianying:addRelatedSkill(y_lianying_card)
y_lukang:addSkill(y_zhudi)
y_lukang:addSkill(y_jueyan)
y_lukang:addRelatedSkill(y_powei)]]
Fk:loadTranslationTable{

  ["y_lukang"] = "陆抗/没测试",
  ["designer:y_lukang"] = "樱之下",
  ["y_zhudi"] = "筑堤",
  [":y_zhudi"] = "游戏开始时，你将5张【水淹七军】装备依次暗置于你的装备栏。<br>"..
  "<font color='grey'>【水淹七军】<br> 装备牌<br /><b>牌效果</b>：当你失去一张【水淹七军】装备牌时，你可以发动一次【水淹七军】。",
  ["y_jueyan"] = "决堰",
  [":y_jueyan"] = "觉醒技，当一名角色回合结束时，若你有空装备栏，则你失去1点体力上限，然后获得“连营”、“怀柔”、“破围”。",
  ["y_powei"] = "破围",
  [":y_powei"] = "回合开始时，你可以废除一个装备栏并替换为一个手牌区，每个手牌区的牌数独立计算。",
  ["#y_powei-abort"] = "破围：选择要废除的装备栏",
  ["@@wuqi"] = "武器栏",
  ["@@fangju"] = "防具栏",
  ["@@-1"] = "-1栏",
  ["@@+1"] = "+1栏",
  ["@@baowu"] = "宝物栏",

}
Fk:loadTranslationTable{
  ["lzml"] = "ﻬ零之魔力",
}

local o__simazhao = General(extension, "o__simazhao", "jin", 3)
  local o__zhaoxin = fk.CreateTriggerSkill{
  name = "o__zhaoxin",
  anim_type = "control",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target and not player:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#o__zhaoxin-ask")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:showCards(player.player_cards[Player.Hand])
    local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return (p:getHandcardNum() <= player:getHandcardNum()) end), Util.IdMapper)
    if #targets > 0 then
      local to = room:getPlayerById(room:askForChoosePlayers(player, targets, 1, 1, "#o__zhaoxin-choose", self.name, false)[1])
      U.swapHandCards(room, player, player, to, self.name)
    end
  end,
  }
  local o__suzhi = fk.CreateTriggerSkill{
  name = "o__suzhi",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.CardUsing, fk.DamageCaused, fk.AfterCardsMove, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) then
      if event == fk.CardUsing then
        return target == player and data.card.type == Card.TypeTrick and (not data.card:isVirtual() or #data.card.subcards == 0)
      elseif event == fk.DamageCaused then
        return target == player and data.card and (data.card.trueName == "slash" or data.card.name == "duel") and not data.chain
      elseif event == fk.AfterCardsMove then
        for _, move in ipairs(data) do
          if move.from and move.from ~= player.id and move.moveReason == fk.ReasonDiscard then
            --FIXME:国战暂时没有同时两名角色弃置牌的情况，先鸽
            local from = room:getPlayerById(move.from)
            if from and not (from.dead or from:isNude()) then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                  self.cost_data = move.from
                  return true
                end
              end
            end
          end
        end
      elseif event == fk.TurnEnd then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TurnEnd then
      room:notifySkillInvoked(player, self.name)
      room:setPlayerMark(player, "@@ld__fankui_simazhao", 1)
      room:handleAddLoseSkills(player, "ld__simazhao__fankui", nil)
      return false
    else
      player:broadcastSkillInvoke(self.name)
      if event == fk.CardUsing then
        room:notifySkillInvoked(player, self.name, "drawcard")
        player:drawCards(1, self.name)
      elseif event == fk.DamageCaused then
        room:notifySkillInvoked(player, self.name, "offensive")
        room:doIndicate(player.id, {data.to.id})
        data.damage = data.damage + 1
      elseif event == fk.AfterCardsMove then
        room:notifySkillInvoked(player, self.name, "control")
        room:doIndicate(player.id, {self.cost_data})
        local card = room:askForCardChosen(player, room:getPlayerById(self.cost_data), "he", self.name)
        room:obtainCard(player.id, card, false, fk.ReasonPrey)
      end
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@ld__fankui_simazhao") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@ld__fankui_simazhao", 0)
    room:handleAddLoseSkills(player, "-ld__simazhao__fankui", nil)
  end,
  }
  local o__suzhi_target = fk.CreateTargetModSkill{
  name = "#o__suzhi_target",
  frequency = Skill.Compulsory,
  bypass_distances = function(self, player, skill, card)
    return player:hasSkill(o__suzhi) and player.phase ~= Player.NotActive  and
    card and card.type == Card.TypeTrick and (not card:isVirtual() or #card.subcards == 0)
  end,
  }
  local o__fankui = fk.CreateTriggerSkill{
  name = "o__simazhao__fankui",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.from and not data.from.dead then
      if data.from == player then
        return #player.player_cards[Player.Equip] > 0
      else
        return not data.from:isNude()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    room:doIndicate(player.id, {from.id})
    local flag =  from == player and "e" or "he"
    local card = room:askForCardChosen(player, from, flag, self.name)
    room:obtainCard(player.id, card, false, fk.ReasonPrey)
  end
  }
  o__suzhi:addRelatedSkill(o__suzhi_target)
  o__simazhao:addSkill(o__zhaoxin)
  o__simazhao:addSkill(o__suzhi)
  o__simazhao:addRelatedSkill(o__fankui)
  Fk:loadTranslationTable{
  ["o__simazhao"] = "司马昭",
  ["designer:o__simazhao"] = "ﻬ零之魔力",

  ["o__zhaoxin"] = "昭心",
  [":o__zhaoxin"] = "当你受到伤害后，你可展示所有手牌，然后与一名手牌数不大于你的角色交换手牌。",
  ["#o__zhaoxin-ask"] = "昭心：你可以展示所有手牌，然后与一名手牌数不大于你的角色交换手牌",
  ["#o__zhaoxin-choose"] = "昭心：选择一名手牌数不大于你的角色，与其交换手牌",

  ["o__suzhi"] = "夙智",
  [":o__suzhi"] = "锁定技，你执行【杀】或【决斗】的效果而造成伤害时，此伤害+1；2.你使用非转化的锦囊牌时摸一张牌且无距离限制；"..
  "3.其他角色的牌被弃置后，你获得其一张牌。回合结束时，你获得“反馈”直至回合开始。",
  ["@@o__fankui_simazhao"] = "夙智 反馈",

  ["o__simazhao__fankui"] = "反馈",
  [":o__simazhao__fankui"] = "当你受到伤害后，你可获得来源的一张牌。",
}
local lzml__gaowang = General(extension, "lzml__gaowang", "qun", 4)
local lzml__anruo = fk.CreateViewAsSkill{
  name = "lzml__anruo",
  pattern = "peach,slash,jink,nullification",
  card_filter = function(self, to_select, selected, player)
    if #selected == 1 then
      return Fk:getCardById(to_select):compareSuitWith(Fk:getCardById(selected[1]))
    else
      local suit = Fk:getCardById(to_select).suit
      local c
      if suit == Card.Heart then
        c = Fk:cloneCard("peach")
      elseif suit == Card.Diamond then
        c = Fk:cloneCard("fire__slash")
      elseif suit == Card.Club then
        c = Fk:cloneCard("jink")
      elseif suit == Card.Spade then
        c = Fk:cloneCard("nullification")
      else
        return false
      end
      return (Fk.currentResponsePattern == nil and c.skill:canUse(player, c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local suit = Fk:getCardById(cards[1]).suit
    local c
    if suit == Card.Heart then
      c = Fk:cloneCard("peach")
    elseif suit == Card.Diamond then
      c = Fk:cloneCard("fire__slash")
    elseif suit == Card.Club then
      c = Fk:cloneCard("jink")
    elseif suit == Card.Spade then
      c = Fk:cloneCard("nullification")
    else
      return nil
    end
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
}
local lzml__anruo_card = fk.CreateTriggerSkill{
  name = "#lzml__anruo_card",
  events = {fk.CardUseFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and table.contains(data.card.skillNames, "lzml__anruo") and #data.card.subcards == 1 
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(table.filter(room:getOtherPlayers(player, false), function(p)
      return not p:isAllNude() end), Util.IdMapper), 1, 1, "#lzml__anruo-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local id = room:askForCardChosen(player, to, "hej", self.name)
    room:obtainCard(player.id, id, false, fk.ReasonPrey)
  end,
}
lzml__anruo:addRelatedSkill(lzml__anruo_card)
lzml__gaowang:addSkill(lzml__anruo)
Fk:loadTranslationTable{
  ["lzml__gaowang"] = "高望",
  ["designer:lzml__gaowang"] = "ﻬ零之魔力",

  ["lzml__anruo"] = "安弱",
  [":o__zhaoxin"] = "你可以将一张牌的花色按以下规则使用或打出:红桃当【桃】;方块当火【杀】;梅花当【闪】;黑桃当【无懈可击】。"..
  "当你以此法使用或打出牌时,你可以获得一名其他角色的一张牌;",
  ["#lzml__anruo-choose"] = "安弱：你可以获得一名其他角色区域内一张牌",

}


Fk:loadTranslationTable{
  ["sxj"] = "数学家",
}
local sxj__xujie = General(extension, "sxj__xujie", "qun", 4)
sxj__xujie.hidden = true
local sxj__xinxue = fk.CreateActiveSkill{
  name = "sxj__xinxue",
  card_num = 1,
  target_num = 0,
  prompt = "#sxj__xinxue",
  derived_piles = "sxj__zhi",
  times = function(self)
    return Self.phase == Player.Play and 3 - Self:usedSkillTimes(self.name, Player.HistoryPhase) 
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < 4 and #player:getPile("sxj__zhi") < 6
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:addToPile(self.name, effect.cards, true, self.name, player.id)
    if player.dead or #player:getPile(self.name) == 0 then return end
    if player:getMark(self.name) == 0 then
      room:setPlayerMark(player, self.name, U.getUniversalCards(room, "bt"))
    end
    local cards = table.filter(player:getMark(self.name), function (id)
      return table.find(player:getPile("sxj__zhi"), function (id2)
        return Fk:getCardById(id).name == Fk:getCardById(id2).name
      end)
    end)
  end,
}
local sxj__xinxue_card = fk.CreateTriggerSkill{
  name = "#sxj__xinxue_card",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sxj__xinxue) and  #player:getPile("#sxj__zhi") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = table.filter(player:getPile("sxj__zhi"), function (id)
      return Fk:getCardById(id).trueName == data.card.trueName
    end)
    if #cards > 0 then
      data.nullifiedTargets = table.map(room:getAlivePlayers(), Util.IdMapper)
    room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, sxj__xinxue.name, nil, true, player.id)
    player:drawCards(2, sxj__xinxue.name)
    end
  end,
}
sxj__xinxue:addRelatedSkill(sxj__xinxue_card)
sxj__xujie:addSkill(sxj__xinxue)
local sxj__yinren = fk.CreateTriggerSkill{
  name = "sxj__yinren",

}
sxj__xujie:addSkill(sxj__yinren)
Fk:loadTranslationTable{
  ["sxj__xujie"] = "徐阶",
  ["sxj__xinxue"] = "心学",
  [":sxj__xinxue"] = "出牌阶段限三次，你可以将一张牌置于武将牌上称为【知】，你至多拥有五张且不同名的【知】；"..
  "当你使用或打出【知】中存在的牌名时，你可以弃置一张此牌名的【知】，并摸两张牌，",
  ["sxj__yinren"] = "隐忍",
  [":sxj__yinren"] = "。",
}




















return extension  